package com.maimao.kill.utils;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import org.springframework.stereotype.Component;

import static com.maimao.core.constant.Constants.UNDER_LINE;
import static com.maimao.core.constant.Constants.UNDER_LINE_STR;

/**
 * @author MaoLin Wang
 * @date 2021/4/13 10:48 下午
 */
@Component
public class KillUtils {

    /**
     * 生成访问秒杀接口的md5串 md5(killId+userId+salt+uuid)
     *
     * @param killId 秒杀id
     * @param userId 用户id
     * @param salt   固定盐值
     */
    public String md5(Long killId, Long userId, String salt) {
        String key = killId + UNDER_LINE_STR + userId + UNDER_LINE_STR + salt + uuid();
        return SecureUtil.md5(key);
    }

    private String uuid() {
        return IdUtil.fastSimpleUUID();
    }

}